package poker

import "strconv"

const (
	SUIT_BLOCK = iota + 1 // 方块
	SUIT_CLUB             // 梅花
	SUIT_HEARD            // 红心
	SUIT_SPADE            // 黑桃
	SUIT_JOKER            // 鬼牌
)

type Card struct {
	suit     int `value:"0~5"`
	value    int `value:"1~15,remark:"14->、15->大王"`
	maxValue int `value:"1~15,remark:"整副牌最大的牌值"`
}

func NewCard(suit, value, maxValue int) *Card {
	return &Card{suit: suit, value: value, maxValue: maxValue}
}

func (this *Card) Suit() int {
	return this.suit
}

func (this *Card) Value() int {
	return this.value
}
func (this *Card) MaxValue() int {
	return this.maxValue
}

func (this *Card) ValueName() string {
	value := this.Value()
	switch value {
	case 1:
		return "A"
	case 11:
		return "J"
	case 12:
		return "Q"
	case 13:
		return "K"
	case 14:
		return "小王"
	case 15:
		return "大王"

	}
	name := strconv.Itoa(int(value))
	return name
}

func (this *Card) Point() int {
	value := this.Value()
	if value > 9 {
		return 0
	}
	return int(value)
}

func (this *Card) Equals(card *Card) bool {
	return this.Value() == card.Value()
}

func (this Card) Gt(card *Card) bool {
	if this.Equals(card) { // 牌值相同比较花色
		// 1：方 3：梅 2：红 4：黑
		return this.Suit() > card.Suit()
	}

	if this.Value() <= this.MaxValue() {
		if card.Value() <= this.MaxValue() {
			return this.Value() > card.Value()
		}
		return true
	}
	if card.Value() <= this.MaxValue() {
		return false
	}
	return this.Value() > card.Value()
}
